/**
 * @Author: lifuzhao
 * @Date: 2019-07-18
 * @Project: driver
 */
import store from '../vuex/index'
import autoTitle from './decorators/autoTitle'
import {Message} from "element-ui"

class Guard {
  constructor(Vue) {
    this.instance = Vue
  }
  
  @autoTitle
  beforeEach({fullPath, meta}, from, next) {
    let {getters} = store
    if (!meta) {
      next()
    } else {
      if (meta.hasOwnProperty('auth')) {
        console.log(getters)
        if (meta.auth.includes(getters.gradeOrigin)) {
          next()
        } else {
          Message.warning('无权访问：' + (meta.title || fullPath) + '页面')
          next('/order')
        }
      } else {
        next()
      }
    }
  }
}

export default Guard
